package com.bah.tract.client.ui;

import java.util.List;

import javax.swing.DefaultComboBoxModel;

import com.bah.tract.service.Task;

public class TaskComboModel extends DefaultComboBoxModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public TaskComboModel(final List<Task> tasks) {
		addElement(null);
		for (final Task task : tasks) {
			addElement(new TaskLabel(task));
		}
	}

	public class TaskLabel {

		private final Task mTask;

		@Override
		public final int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime
					* result
					+ ((mTask == null) ? 0 : mTask.getIdentifyingProperty()
							.hashCode());
			return result;
		}

		@Override
		public final boolean equals(final Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final TaskLabel other = (TaskLabel) obj;
			if (!getOuterType().equals(other.getOuterType())) {
				return false;
			}
			if (mTask == null) {
				if (other.mTask != null) {
					return false;
				}
			} else if (!mTask.getIdentifyingProperty().equals(
					other.mTask.getIdentifyingProperty())) {
				return false;
			}
			return true;
		}

		public final Task getTask() {
			return mTask;
		}

		public TaskLabel(final Task task) {
			mTask = task;
		}

		@Override
		public String toString() {
			return mTask.getLabel();
		}

		private TaskComboModel getOuterType() {
			return TaskComboModel.this;
		}

	}

}
